
include std/unittest.e
include qt/debug_utils.e


object _ = 0

-- TEST_QUIET (so no output), TEST_SHOW_FAILED_ONLY and TEST_SHOW_ALL
--~ set_test_verbosity(TEST_SHOW_ALL)


--~ :global procedure OutputDebugString(sequence text)
--~ :procedure log_file(object fn, sequence lines, sequence mode="a")




test_equal("if21", 1, if2( {1, 1, 12} ))
test_equal("if2", 2, if2( {0, 11, 2} ))
test_equal("rjustlen 1.1",  "         1.1",rjustlen("1.1", 12 ))
test_equal("rjustlen 1.2 ", "         1.2",  rjustlen("1.2", 12))
test_equal("rjustlen 1.3 ", "        1.3 ",  rjustlen("1.3 ", 12," "))
test_equal("rjustlen 1.4 - ", "1.4 ",  rjustlen("1.4 ", 12,""))
test_equal("rjustlen 15 +", "++++++ 15",  rjustlen(" 15", 9,"+"))
test_equal("rjustlen 1.6 ", " 1.6 ",  rjustlen("1.6 ", 5))

test_equal("wrap_len 4", {"1234"},  wrap_len("1234", 4, 0))
test_equal("wrap_len 12", {"1234"},  wrap_len("1234", 12, 0))
test_equal("wrap_len 42", {"1234","1234"},  wrap_len("12341234", 4, 0))
test_equal("wrap_len 22", {"12","34","12","34","3"},  wrap_len("123412343", 2, 0))
test_equal("wrap_len 1", {"1","2","3","4"},  wrap_len("1234", 1, 0))
--hardly an exaustive test
test_equal("wrap_len 1", {"split at ","word bound"},  wrap_len("split at word bound", 10, 1))
--breaks down at small numbers but will probably never wrap less than 20?
test_equal("wrap_len 1", {"split ","at wor", "d boun","d "}
     ,wrap_len("split at word bound ", 6, 1))
test_equal("wrap_len 1", {"split at word ","bound no matter ","what"}
     ,wrap_len("split at word bound no matter what", 16, 1))
test_equal("wrap_len 1", {"split at word bound no ","matter what"}
     ,wrap_len("split at word bound no matter what", 26, 1))
test_equal("wrap_len 1", {"split at word bound \n","no matter what"}
        ,wrap_len("split at word bound \nno matter what", 21, 1))


test_equal("repeat 1", {"12","12","12"},  repeat("12", 3))
--~ test_equal("repeat 1", "12 12 12",  implode(repeat("12", 3),' '))  -- '' empty char nfg?


 test_equal("comafy(1234", "1,234"
                 ,comafy(1234) )

 test_equal("comafy(1234", "12,340.00"
                 ,comafy(12340, "%4.2f") )
 test_equal("comafy(1", "1"
                 ,comafy(1, "%1.0f") )


 test_equal("itoa, 16", "A" ,itoa(10, 16) )
 test_equal("itoa", "12" ,itoa(12) )
 test_equal("itoa, 15", "1111" ,itoa(15, 2) )
 test_equal("itoa, 15.02", "1111" ,itoa(15.02, 2) )
 test_equal("ftoa", "12.000" ,ftoa(12,3) )
 test_equal("atoi", 12 ,atoi("12") )
 test_equal("atoi {0,4}", {0,4} ,atoi("{0,4}") )
 
 test_equal("meg_a_num s1025", "1KiB" ,meg_a_num("1,025") )
 test_equal("meg_a_num 1025", "1KiB" ,meg_a_num(1025) )
 
 test_equal("meg_a_num 1021", "1021" ,meg_a_num(1021) )
 
	 
 test_equal("decompose(7)", {4, 2, 1}
                 ,decompose(7) ) 
 test_equal("decompose(15, 2)", {8, 4, 2, 1}
                 ,decompose(15, 2) ) 
 test_equal("decompose(17, 16)", {16 ,1} --needs to be fixed
                 ,decompose(17, 16) ) 

test_report()
